<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登陆</title>

    <!-- bootstrap -->
    <link rel="stylesheet" href="./assets/css/bootstrap.min.css" />

    <!-- animate.css -->
    <link rel="stylesheet" href="./assets/css/animate.min.css" />

    <!-- MUI -->
    <link rel="stylesheet" href="./assets/plugins/mui/css/mui.min.css">

    <!-- 引入bootstrapValidator表单验证插件 -->
    <link rel="stylesheet" href="./assets/plugins/bootstrap-validator/bootstrapValidator.min.css">

    <!-- 重置样式 -->
    <link rel="stylesheet" href="./assets/css/reset.css" />

    <!-- 公共样式 -->
    <link rel="stylesheet" href="./assets/css/common.css" />

    <!-- 页面独立的 -->
    <link rel="stylesheet" href="./assets/css/UserLogin.css" />
</head>

<body>
    <!-- 用户信息 -->
    <div class="user">
        <div class="avatar wow fadeInUp">
            <img src="./assets/images/avatar.png" />
        </div>

        <div class="notice wow fadeInUp" data-wow-delay="100ms">请填写已有账号或新注册账号</div>
    </div>

    <form class="login wow fadeInUp" data-wow-delay="200ms" method="post">
        <div class="form-group">
            <label for="mobile">手机号码</label>
            <input type="text" class="form-control" id="mobile" name="mobile" value="" placeholder="请输入手机号码"
                required />
        </div>

        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" class="form-control" id="password" value="" name="password" placeholder="请输入密码"
                required />
        </div>

        <div class="action">
            <button class="btn" type="submit">登陆</button>
        </div>

        <div class="action" style="text-align: center;">
            <a href="register.html">注册</a>
        </div>
    </form>
</body>

</html>
<!-- jquery  -->
<script src="./assets/js/jquery.min.js"></script>

<!-- bootstrap -->
<script src="./assets/js/bootstrap.min.js"></script>

<!-- wow.js -->
<script src="./assets/js/wow.min.js"></script>

<!-- MUI -->
<script src="./assets/plugins/mui/js/mui.min.js"></script>

<!-- 引入bootstrapValidator表单验证插件 -->
<script src="./assets/plugins/bootstrap-validator/bootstrapValidator.min.js"></script>

<!-- axios请求 -->
<script src="./assets/plugins/axios/axios.js"></script>
<script src="./assets/plugins/axios/request.js"></script>

<!-- cookie -->
<script src="./assets/plugins/cookie.js"></script>

<script>
    //实例化wow.js
    new WOW().init();

    // 对form元素绑定校验规则：
    $("form").bootstrapValidator({
        // 图标
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        // 字段
        fields: {
            mobile: {
                validators: {
                    notEmpty: { // 非空校验
                        message: '手机号码不能为空!'
                    },
                    regexp: { //正则校验
                        regexp: /^1[356789]\d{9}$/,
                        message: '手机号码格式错误'
                    },
                }
            },
            password: {
                validators: {
                    notEmpty: { // 非空校验
                        message: '密码不能为空!'
                    },
                    stringLength: { // 长度校验
                        min: 4,
                        max: 16,
                        message: '密码长度%s~%s个字符！'
                    }
                }
            }
        }
    }).on('success.form.bv', function (e) {
        e.preventDefault();
    })

    $("form").submit(async function (e) {

        let result = await POST({
            url: 'business/login', params: {
                mobile: $("#mobile").val(),
                password: $("#password").val()
            }
        })
        console.log(result);

        if (result.code == 1) {
            // 存储用户信息
            cookie.set('Business', JSON.stringify(result.data))
            mui.toast(result.msg, { duration: 'long', type: 'div' });
            setTimeout(() => {
                location.href = 'my.html'
            }, 1000)
        } else {
            mui.toast(result.msg, { duration: 'long', type: 'div' });
            $('form').data('bootstrapValidator').resetForm(true); // 重置校验
        }
    })
</script>